package com.leon.learnenginespace.drools.utils.operation.impl;

import com.leon.learnenginespace.drools.utils.operation.IOperationBase;
import org.springframework.stereotype.Component;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 匹配某个字符
 * @author lhy
 */
@Component
public class MatcherOperation implements IOperationBase {
    /**
     * v[1]存在 v[2]中的某个字符
     * @param v
     * @return
     */
    @Override
    public Boolean operation(String dataType,Object ...v) {
        try {
            Object v1 = v[0];
            Object v2 = v[1];
            String regex = "[" + v2 +"]|\n|\r|\t";
            if(v1 == null){
                return false;
            }
            Pattern pattern = Pattern.compile(regex);
            Matcher matcher = pattern.matcher(String.valueOf(v1));

            return matcher.find(0);
       }catch (Exception e){
           return false;
       }
    }
}
